package com.ycky.starlink.controller.pms;

import com.ycky.common.core.controller.BaseController;
import com.ycky.common.core.domain.AjaxResult;
import com.ycky.common.core.page.TableDataInfo;
import com.ycky.starlink.domain.entity.pms.PmsBrand;
import com.ycky.starlink.domain.param.PmsBrandParam;
import com.ycky.starlink.service.PmsBrandService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @description: 商品品牌管理
 * @author: cjj
 * @date: 2025/3/25 17:32
 **/
@RestController
@Api(tags = "PmsBrandController")
@Tag(name = "PmsBrandController", description = "商品品牌管理")
@RequestMapping("/brand")
public class PmsBrandController extends BaseController {
    @Autowired
    private PmsBrandService brandService;

    @ApiOperation(value = "获取全部品牌列表")
    @GetMapping("/listAll")
    public TableDataInfo list() {
        startPage();
        List<PmsBrand> list = brandService.listAllBrand();
        return getDataTable(list);
    }

    @ApiOperation(value = "添加品牌")
    @RequestMapping(value = "/create", method = RequestMethod.POST)
    @ResponseBody
    public AjaxResult create(@Validated @RequestBody PmsBrandParam pmsBrand) {
        int count = brandService.createBrand(pmsBrand);
        if (count > 0) {
            return AjaxResult.success(count);
        } else {
            return AjaxResult.error();
        }
    }

    @ApiOperation(value = "更新品牌")
    @RequestMapping(value = "/update/{id}", method = RequestMethod.POST)
    @ResponseBody
    public AjaxResult update(@PathVariable("id") Long id,
                             @Validated @RequestBody PmsBrandParam pmsBrandParam) {
        int count = brandService.updateBrand(id, pmsBrandParam);
        if (count > 0) {
            return AjaxResult.success(count);
        } else {
            return AjaxResult.error();
        }
    }

    @ApiOperation(value = "删除品牌")
    @RequestMapping(value = "/delete/{id}", method = RequestMethod.GET)
    @ResponseBody
    public AjaxResult delete(@PathVariable("id") Long id) {
        int count = brandService.deleteBrand(id);
        if (count > 0) {
            return AjaxResult.success(count);
        } else {
            return AjaxResult.error();
        }
    }

    @ApiOperation(value = "根据品牌名称分页获取品牌列表")
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    @ResponseBody
    public TableDataInfo getList(@RequestParam(value = "keyword", required = false) String keyword,
                                                      @RequestParam(value = "showStatus",required = false) Integer showStatus,
                                                      @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                      @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize) {
        startPage();
        List<PmsBrand> list = brandService.listBrand(keyword,showStatus,pageNum, pageSize);
        return getDataTable(list);
    }

    @ApiOperation(value = "根据编号查询品牌信息")
    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    @ResponseBody
    public AjaxResult getItem(@PathVariable("id") Long id) {
        return AjaxResult.success(brandService.getBrand(id));
    }

    @ApiOperation(value = "批量删除品牌")
    @RequestMapping(value = "/delete/batch", method = RequestMethod.POST)
    @ResponseBody
    public AjaxResult deleteBatch(@RequestParam("ids") List<Long> ids) {
        int count = brandService.deleteBrand(ids);
        if (count > 0) {
            return AjaxResult.success(count);
        } else {
            return AjaxResult.error();
        }
    }

    @ApiOperation(value = "批量更新显示状态")
    @RequestMapping(value = "/update/showStatus", method = RequestMethod.POST)
    @ResponseBody
    public AjaxResult updateShowStatus(@RequestParam("ids") List<Long> ids,
                                       @RequestParam("showStatus") Integer showStatus) {
        int count = brandService.updateShowStatus(ids, showStatus);
        if (count > 0) {
            return AjaxResult.success(count);
        } else {
            return AjaxResult.error();
        }
    }

    @ApiOperation(value = "批量更新厂家制造商状态")
    @RequestMapping(value = "/update/factoryStatus", method = RequestMethod.POST)
    @ResponseBody
    public AjaxResult updateFactoryStatus(@RequestParam("ids") List<Long> ids,
                                          @RequestParam("factoryStatus") Integer factoryStatus) {
        int count = brandService.updateFactoryStatus(ids, factoryStatus);
        if (count > 0) {
            return AjaxResult.success(count);
        } else {
            return AjaxResult.error();
        }
    }
}
